package cn.fl.insurance.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.insurance.condition.InsPlcTypDtlQueryCondition;
import cn.fl.insurance.dto.InsPlcTypDtlDTO;
import cn.fl.insurance.service.IInsPlcTypDtlApiService;
import cn.fl.insurance.service.IInsPlcTypDtlService;
import cn.fl.insurance.transform.InsPlcTypDtlVOTransform;
import cn.fl.insurance.vo.InsPlcTypDtlVO;

/**
 * @Description: 保单险种明细 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class InsPlcTypDtlServiceImpl implements IInsPlcTypDtlService {

    /**
     * 日志
     */
    @SuppressWarnings("unused")
    private static final Logger logger = LoggerFactory.getLogger(InsPlcTypDtlServiceImpl.class);

    /**
     * TODO 自定义 API 暴露服务
     */
    @Autowired
    private IInsPlcTypDtlApiService insPlcTypDtlApiService;

    @Override
    public InsPlcTypDtlVO selectById(Long id) throws BaseException {
        if (StringUtils.isEmpty(id)) return null;
        InsPlcTypDtlDTO dto = this.insPlcTypDtlApiService.selectInsPlcTypDtlById(id);
        return InsPlcTypDtlVOTransform.toVO(dto);
    }

    @Override
    public Long add(InsPlcTypDtlVO entity) throws BaseException {
        if (null == entity) return null;
        return this.insPlcTypDtlApiService.addInsPlcTypDtl(InsPlcTypDtlVOTransform.toDTO(entity));
    }

    @Override
    public boolean removeByIds(List<Long> ids) throws BaseException {
        if (CollectionUtils.isEmpty(ids)) return false;
        return this.insPlcTypDtlApiService.removeInsPlcTypDtlByIds(ids, CurrentThreadContext.getCurrentUserId());
    }

    @Override
    public boolean modify(InsPlcTypDtlVO entity) throws BaseException {
        if (null == entity) return false;
        return this.insPlcTypDtlApiService.modifyInsPlcTypDtl(InsPlcTypDtlVOTransform.toDTO(entity));
    }

    @Override
    public Pager searchListPage(Pager page) throws BaseException {
        if (null == page) page = new Pager();
        page=this.insPlcTypDtlApiService.searchInsPlcTypDtlListPage(page, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        if(CollectionUtils.isNotEmpty(page.getResultList())){
            page.setResultList(InsPlcTypDtlVOTransform.toVOList((List<InsPlcTypDtlDTO>) page.getResultList()));
        }
        return page;
    }

    @Override
    public List<InsPlcTypDtlVO> searchList(InsPlcTypDtlQueryCondition condition) throws BaseException {
        if(null!=condition){
            condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        }
        return InsPlcTypDtlVOTransform.toVOList(this.insPlcTypDtlApiService.searchInsPlcTypDtlList(condition));
    }

}
